// DProposal.cs
//
// Copyright (c) 2007 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;

using Supremacy.Entities;
using Supremacy.Game;

namespace Supremacy.Diplomacy
{
    public interface IProposal
    {
        TurnNumber TurnSent { get; }
        Civilization Sender { get; }
        Civilization Recipient { get; }
        IList<IClause> Clauses { get; }
    }

    public static class ProposalExtensions
    {
        public static bool IsGift(this IProposal proposal)
        {
            if (proposal == null)
                return false;
            bool isGift = false;
            foreach (var clause in proposal.Clauses)
            {
                switch (clause.ClauseType)
                {
                    case ClauseType.RequestBreakAgreement:
                    case ClauseType.RequestEndEmbargo:
                    case ClauseType.RequestGiveCredits:
                    case ClauseType.RequestGiveResources:
                    case ClauseType.RequestHonorMilitaryAgreement:
                    case ClauseType.RequestMapData:
                    case ClauseType.RequestStopPiracy:
                    case ClauseType.RequestWithdrawTroops:
                    case ClauseType.TreatyAlliance:
                    case ClauseType.TreatyCeaseFire:
                    case ClauseType.TreatyDeclareWar:
                    case ClauseType.TreatyMilitaryPact:
                    case ClauseType.TreatyPeace:
                    case ClauseType.TreatyResearchPact:
                    case ClauseType.TreatyTradePact:
                        return false;
                    default:
                        isGift = true;
                        break;
                }
            }
            return isGift;
        }

        public static bool IsDemand(this IProposal proposal)
        {
            if (proposal == null)
                return false;
            bool isDemand = false;
            foreach (var clause in proposal.Clauses)
            {
                switch (clause.ClauseType)
                {
                    case ClauseType.OfferBreakAgreement:
                    case ClauseType.OfferEndEmbargo:
                    case ClauseType.OfferGiveCredits:
                    case ClauseType.OfferGiveResources:
                    case ClauseType.OfferHonorMilitaryAgreement:
                    case ClauseType.OfferMapData:
                    case ClauseType.OfferStopPiracy:
                    case ClauseType.OfferWithdrawTroops:
                    case ClauseType.TreatyAlliance:
                    case ClauseType.TreatyCeaseFire:
                    case ClauseType.TreatyDeclareWar:
                    case ClauseType.TreatyMilitaryPact:
                    case ClauseType.TreatyPeace:
                    case ClauseType.TreatyResearchPact:
                    case ClauseType.TreatyTradePact:
                        return false;
                    default:
                        isDemand = true;
                        break;
                }
            }
            return isDemand;
        }

        public static bool HasTreaty(this IProposal proposal)
        {
            if (proposal == null)
                return false;
            foreach (var clause in proposal.Clauses)
            {
                switch (clause.ClauseType)
                {
                    case ClauseType.TreatyAlliance:
                    case ClauseType.TreatyCeaseFire:
                    case ClauseType.TreatyDeclareWar:
                    case ClauseType.TreatyMilitaryPact:
                    case ClauseType.TreatyPeace:
                    case ClauseType.TreatyResearchPact:
                    case ClauseType.TreatyTradePact:
                        return true;
                }
            }
            return false;
        }
    }
}